package post;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yxnote.PMF;

public class Update extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String id = req.getParameter("id");
        String title = req.getParameter("title");
        String category = req.getParameter("category");
        String content = req.getParameter("content");
        PersistenceManager pm = PMF.get().getPersistenceManager();
        
        try {
            Post p = pm.getObjectById(Post.class, Long.valueOf(id));
            p.setTitle(title)
                .setCategory(category)
                .setContent(content);
        } finally {
            pm.close();
        }
        
        resp.sendRedirect("/post/view.jsp?id=" + id);
    }
}
